/*=+--+=#=+--     Unmanned Aerial System Management Software      --+=#=+--+=#*\
|          Copyright (C) 2011 Regents of the University of Colorado.           |
|                             All Rights Reserved.                             |

     This program is free software: you can redistribute it and/or modify
     it under the terms of the GNU General Public License version 2 as
     published by the Free Software Foundation.

     This program is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License for more details.

     You should have received a copy of the GNU General Public License
     along with this program.  If not, see <http://www.gnu.org/licenses/>.

            Jack Elston                       Cory Dixon                        
|           elstonj@colorado.edu              dixonc@colorado.edu              |
|                                                                              |
\*=+--+=#=+--                 --+=#=+--+=#=+--                    --+=#=+--+=#*/

#ifndef __NETWORK_LAYER_MANAGER_H
#define __NETWORK_LAYER_MANAGER_H

#include "LayerManager.h"

#define NETWORK_ALPHA 0.5

/*<-------Defines--------->*/
/*<------End Defines------>*/

typedef struct _NetworkLink 
{
	String         name;
	guint          ind1; // client ind source
	guint          ind2; // client ind dest

	gfloat         scale;
	gboolean       draw;

	uint32_t       cap_color; // rgba
	uint32_t       maxU_color; // rgba
	uint32_t       usage_color; // rgba

	double         x1; // x-position of node 1 in NetworkLayer frame
	double         y1; // y-position of node 1 in NetworkLayer frame
	double         x2; // x-position of node 2 in NetworkLayer frame
	double         y2; // y-position of node 2 in NetworkLayer frame

	bool           timed_out;
	float          capacity;
	float          usage;     // total usage rate of Rx and Tx
	float          max_usage;

	float          capWidth;
	float          useWidth;
	float          maxUWidth;

	GooCanvasItem  *linkG; // capacity of link
	GooCanvasItem  *capacity_line; // capacity of link
	//GooCanvasItem  *max_usage_line;    // throughput 
	GooCanvasItem  *usage_line;    // throughput 

	_NetworkLink() {
		capWidth = useWidth = 1;
		linkG = capacity_line = usage_line = 0;
	}
} NetworkLink;


class NetworkLayerManager : public LayerManager
{
	private:
		void update_links();
		void update_links_TEST();
		Client* get_client(Client * a_client, int linkInd);

		void create_link_lines(NetworkLink *linkPtr);
		void update_link_lines(NetworkLink *linkPtr);
		
		// first index is destination, how it received from source
		NetworkLink  links[MAX_CLIENTS][MAX_CLIENTS]; 

		uint8_t alpha;  // transparency level from 0-255

	public:
		NetworkLayerManager();
		~NetworkLayerManager();

		virtual void init(GPSMap *map = NULL);
		virtual void updateMap();
		virtual void translate_from_zoomChange(double zoom_factor);

		float  capToLineWidth(float cap); // convert capacity in Mb/s to a line width
		float  rateToLineWidth(float cap, float rate, float capW = -1); // convert rate in B/s to a fractional amount of capToLineWidth

		void set_alpha(double a);   // [0-1]
};

#endif
